package client;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.Serializable;
import java.util.ArrayList;

public class Area implements Serializable {

	private transient Image background;
	private int id;
	private int worldX;
	private int worldY;
	private ArrayList<Creature> enemies;
	private ArrayList<Building> buildings;
	private transient ArrayList<Obstacle> obstacles;

	public Area() {
		enemies = new ArrayList<Creature>();
		buildings = new ArrayList<Building>();
		obstacles = new ArrayList<Obstacle>();
	}
	
	public void addEnemy(Creature enemy){
		enemies.add(enemy);
	}
	
	public void addBuilding(Building building){
		buildings.add(building);
	}
	
	public void addObstacle(Obstacle o){
		obstacles.add(o);
	}
	
	public Image getBackground() {
		return background;
	}

	public void setBackground(Image background) {
		this.background = background;
	}
	
	public void loadBackground(String filename){
		setBackground(GraphicsLoader.loadImage(filename));
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getWorldX() {
		return worldX;
	}

	public void setWorldX(int worldX) {
		this.worldX = worldX;
	}

	public int getWorldY() {
		return worldY;
	}

	public void setWorldY(int worldY) {
		this.worldY = worldY;
	}
	
	public boolean checkCollisions(Rectangle playerBoundingRectangle){
		boolean collision=false;
		for(Obstacle ob : obstacles){
			if(ob.checkCollisions(playerBoundingRectangle)){
				collision=true;
			}
		}
		return collision;
	}
	
	public void paint(Graphics g){
		if (background != null) {
			g.drawImage(background, 0, 0, null);
		}
		for(Obstacle ob : obstacles){
			ob.paint(g);
		}
	}
}
